home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0122_Read Multiple Keys.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  2.4 KB  |  92 lines

  1. {
  2. Unit for reading multiple keys... works brilliantly, 
  3. although I (Scott Tunstall) didn't write it, I think it was
  4. Lou Duchez. Thanks Lou!
  5. }
  6.  
  7. Unit NWKBDINT ;         
  8.  
  9. Interface
  10. Procedure HookKeyBoardInt;              { Take over Keyboard handler }
  11. Procedure UnHookKeyBoardInt;            { Return control back to system }
  12.  
  13.  
  14. Var
  15.    KeyDown : Array[0..127 ] of Boolean ;
  16.  
  17. Implementation
  18. Uses DOS;
  19.  
  20. Var
  21.    OldInt09 : Pointer ;
  22.    ExitSave : Pointer ;
  23.  
  24.  
  25.  
  26.  
  27. {$F+}
  28.  
  29.  
  30. procedure Newint09; assembler;       { new keyboard handler }
  31.   asm
  32.     push ax                           { push registers }
  33.     push bx
  34.     push ds
  35.     mov ax, SEG @Data
  36.     mov ds, ax
  37.     in  al, 60h
  38.     mov bx, ax
  39.     and bx, 007fh                     { switch high bit of BX to zero }
  40.     and al, 80h                       { check high bit of port value }
  41.     jz @press
  42.     @release:                         { high bit = 1: "release" code }
  43.     mov byte ptr keydown[bx], 00h     { write 00 to "down" array element }
  44.     jmp @done
  45.     @press:                           { high bit = 0: "press" code }
  46.     mov byte ptr keydown[bx], 01h     { write 01 to "down" array element }
  47.     @done:
  48.     in al, 61h                        { read port 61h, system ctrl port }
  49.     mov ah, al                        { save value to AH }
  50.     or al, 80h                        { set top bit to "1" - reset kbd }
  51.     out 61h, al                       { write out value to port }
  52.     xchg ah, al                       { put original value back into AL }
  53.     out 61h, al                       { rewrite original value in AL }
  54.     mov al, 20h                       { generate End of Interrupt }
  55.     out 20h, al
  56.     pop ds                            { pop registers }
  57.     pop bx
  58.     pop ax
  59.     iret                              { return }
  60.     end;
  61.  
  62.  
  63.  
  64. Procedure HookKeyBoardInt;            { Take over keyboard }
  65. Var KeyCount: byte;
  66. Begin
  67.      For KeyCount:=0 to 127 do
  68.          KeyDown[KeyCount]:=False;
  69.      GetIntVec(9,OldInt09);
  70.      SetIntVec(9,@NewInt09);
  71. End;
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. Procedure UnHookKeyBoardInt;          { Let system do hard work now }
  79. Begin
  80.      SetIntVec(9,OldInt09);
  81.      Mem[$40:$1c]:=Mem[$40:$1a];      { Flush key buffer so
  82.                                         there's no phantom keys }
  83. End;
  84.  
  85.  
  86.  
  87.  
  88. Begin
  89.      Writeln('Installing NEWKBDINT multiple key handler..');
  90.  
  91. End.
  92.